home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gempp19.zoo / gem++19 / src / rsc_fix.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-28  |  5.6 KB  |  247 lines

  1. /*  rsc_fix.cc   Tue 23 Feb 1993 17:36:42      Warwick Allison
  2.  *      Converted to C++,
  3.  *      Propagated 'header' and 'offset' parameters to all functions.
  4.  *
  5.  *  Based loosely on:
  6.  *        RSCFIX.C        09/16/86                Ric Clayton
  7.  */
  8.  
  9. #include <aesbind.h>
  10. #include "rsc_gobj.h"
  11.  
  12. // Convert a RSC pseudopointer into a real pointer.  Assumes "offset".
  13. #define NIL (-1)
  14. #define RSH(x) (long(x) == NIL ? 0 : ((typeof(x))(long(x)+offset)))
  15.  
  16. // Two different types of position adjustment.
  17. //
  18. // Proportion for forms...
  19. //
  20. #define adj(xywh, siz, scale) \
  21.     ((siz)*((xywh) & 0x00FF) + (((unsigned short)(xywh)) >> 8)*(siz)/(scale))
  22. //
  23. // Standard for menus...
  24. //
  25. #define adj_menu(xywh, siz, scale) \
  26.     ((siz)*((xywh) & 0x00FF) + (((unsigned short)(xywh)) >> 8))
  27.  
  28.  
  29. static void map_tree(OBJECT* tree, int from, int last, int routine(OBJECT&))
  30. // From ProGEM...
  31. {
  32.     /* Initialize to impossible value: */
  33.     /* TAIL won't point to self!       */
  34.     /* Look until final node, or off   */
  35.     /* the end of tree         */ 
  36.     int tmp1=from;
  37.  
  38.     while (from != last && from != NIL) {
  39.         /* Did we 'pop' into this node     */
  40.         /* for the second time?        */
  41.         if (tree[from].ob_tail != tmp1) {
  42.             tmp1 = from;    /* This is a new node       */
  43.             from = NIL;
  44.  
  45.             /* Apply operation, testing  */
  46.             /* for rejection of sub-tree */
  47.             if (routine(tree[tmp1])) from = tree[tmp1].ob_head;
  48.  
  49.             /* Subtree path not taken,   */
  50.             /* so traverse right     */ 
  51.             if (from == NIL) from = tree[tmp1].ob_next;
  52.         } else {
  53.             /* Revisiting parent:    */
  54.             /* No operation, move right  */
  55.             tmp1 = from;
  56.             from = tree[tmp1].ob_next;
  57.         }
  58.     }
  59. }
  60.  
  61. void fix_string(char* text)
  62. // Strip trailing '@' characters from text.
  63. {
  64.     int i=0;
  65.     while (text[i]) i++;
  66.     i--;
  67.     while (i>=0 && text[i]=='@') text[i--]=0;
  68. }
  69.  
  70. static void fix_trindex(RSHDR* header, long offset)
  71. {
  72.     OBJECT** rs_trindex=(OBJECT**)(header->rsh_trindex+offset);
  73.  
  74.     int        i;
  75.     
  76.     for (i = 0; i < header->rsh_ntree; i++) {
  77.         rs_trindex[i] = RSH(rs_trindex[i]);
  78.     }
  79. }
  80.  
  81. static void fix_objects(RSHDR* header, long offset)
  82. {
  83.     OBJECT* rs_object=(OBJECT*)(header->rsh_object+offset);
  84.  
  85.     int         i;
  86.     
  87.     for (i = 0; i < header->rsh_nobs; i++) {
  88.         // Mask off extended type
  89.         switch (rs_object[i].ob_type&0xff) {
  90.           case G_BOX:
  91.           case G_IBOX:
  92.           case G_BOXCHAR:
  93.           case G_USERDEF:
  94.         break;
  95.           case G_STRING:
  96.           case G_TITLE:
  97.           case G_BUTTON:
  98.             rs_object[i].ob_spec = RSH(rs_object[i].ob_spec);
  99.             fix_string((char*)rs_object[i].ob_spec);
  100.         break;
  101.           default:
  102.             // XXX Assume that ALL new object types have a pseudopointer
  103.             // XXX to object-specific data.
  104.             // XXX This is a weakspot in this rsrc_load() reimplementation.
  105.             rs_object[i].ob_spec = RSH(rs_object[i].ob_spec);
  106.         }
  107.     }
  108. }
  109.  
  110. // Global variables for the map_tree routines
  111. static int wchar,hchar,rscw,rsch;
  112. static int titlefound;
  113.  
  114. static int findtitle(OBJECT& o)
  115. {
  116.     if ((o.ob_type&0xff) == G_TITLE) {
  117.         titlefound=1;
  118.         return 0;
  119.     } else
  120.         return 1;
  121. }
  122.  
  123. static int pos_menu(OBJECT& o)
  124. {
  125.     o.ob_x = adj_menu(o.ob_x, wchar, rscw);
  126.     o.ob_y = adj_menu(o.ob_y, hchar, rsch);
  127.     o.ob_width = adj_menu(o.ob_width, wchar, rscw);
  128.     o.ob_height = adj_menu(o.ob_height, hchar, rsch);
  129.     return 1;
  130. }
  131.  
  132. static int pos_form(OBJECT& o)
  133. {
  134.     o.ob_x = adj(o.ob_x, wchar, rscw);
  135.     o.ob_y = adj(o.ob_y, hchar, rsch);
  136.     o.ob_width = adj(o.ob_width, wchar, rscw);
  137.     o.ob_height = adj(o.ob_height, hchar, rsch);
  138.     return 1;
  139. }
  140.  
  141. static void pos_objects(RSHDR* header, long offset, int rscW, int rscH)
  142. {
  143.     rscw=rscW;
  144.     rsch=rscH;
  145.  
  146.     int i;
  147.  
  148.     graf_handle( &wchar, &hchar, &i, &i );
  149.  
  150.     OBJECT* tree;
  151.  
  152.     for (i=0; tree=(OBJECT*)rsc_gobj(header,offset,R_TREE,i); i++) {
  153.         titlefound=0;
  154.         map_tree(tree,0,-1,findtitle);
  155.  
  156.         if (titlefound)
  157.             map_tree(tree,0,-1,pos_menu);
  158.         else
  159.             map_tree(tree,0,-1,pos_form);
  160.     }
  161. }
  162.         
  163. static void fix_tedinfo(RSHDR* header, long offset)
  164. {
  165.     TEDINFO* rs_tedinfo=(TEDINFO*)(header->rsh_tedinfo+offset);
  166.  
  167.     int        i;
  168.  
  169.     for (i = 0; i < header->rsh_nted; i++) {
  170.         rs_tedinfo[i].te_ptext=RSH(rs_tedinfo[i].te_ptext);
  171.         rs_tedinfo[i].te_ptmplt=RSH(rs_tedinfo[i].te_ptmplt);
  172.         rs_tedinfo[i].te_pvalid=RSH(rs_tedinfo[i].te_pvalid);
  173.         fix_string(rs_tedinfo[i].te_ptext);
  174.     }
  175. }
  176.  
  177. static void fix_frstr(RSHDR* header, long offset)
  178. {
  179.     char** rs_frstr=(char**)(header->rsh_frstr+offset);
  180.  
  181.     int        i;
  182.     
  183.     for (i = 0; i < header->rsh_nstring; i++) {
  184.         rs_frstr[i]=RSH(rs_frstr[i]);
  185.         fix_string(rs_frstr[i]);
  186.     }
  187. }
  188.  
  189. static void fix_iconblk(RSHDR* header, long offset)
  190. {
  191. #ifdef ICONBLK_PLUS_2_BUG
  192.     // ICONBLKs in the RSC file are 2 bytes shorter than those defined in gemfast.h
  193. #    define RSHiconblk(x) (*((ICONBLK*)(header->rsh_iconblk+offset+x*(sizeof(ICONBLK)-2))))
  194. #else
  195.     // ICONBLKs are the right size now.
  196. #    define RSHiconblk(x) (*((ICONBLK*)(header->rsh_iconblk+offset+x*(sizeof(ICONBLK)))))
  197. #endif
  198.     int        i;
  199.     
  200.     for (i = 0; i < header->rsh_nib; i++)
  201.     {
  202.         RSHiconblk(i).ib_pmask=RSH(RSHiconblk(i).ib_pmask);
  203.         RSHiconblk(i).ib_pdata=RSH(RSHiconblk(i).ib_pdata);
  204.         RSHiconblk(i).ib_ptext=RSH(RSHiconblk(i).ib_ptext);
  205.         fix_string(RSHiconblk(i).ib_ptext);
  206.     }
  207. }
  208.  
  209. static void fix_bitblk(RSHDR* header, long offset)
  210. {
  211.     BITBLK* rs_bitblk=(BITBLK*)(header->rsh_bitblk+offset);
  212.  
  213.     int        i;
  214.     
  215.     for (i = 0; i < header->rsh_nbb; i++)
  216.         rs_bitblk[i].bi_pdata=RSH(rs_bitblk[i].bi_pdata);
  217. }
  218.  
  219. static void fix_frimg(RSHDR* header, long offset)
  220. {
  221.     char** rs_frimg=(char**)(header->rsh_frimg+offset);
  222.  
  223.     int        i;
  224.     
  225.     for (i = 0; i < header->rsh_nimages; i++)
  226.         rs_frimg[i]=RSH(rs_frimg[i]);
  227. }
  228.  
  229.  
  230. /* this is the only 'exported' function in
  231.  * this module.
  232.  */
  233. void rsc_fix(RSHDR* header, long offset, int rscw, int rsch)
  234. {
  235.     fix_trindex(header,offset);
  236.     fix_objects(header,offset);
  237.     fix_tedinfo(header,offset);
  238.     fix_iconblk(header,offset);
  239.     fix_bitblk(header,offset);
  240.     fix_frstr(header,offset);
  241.     fix_frimg(header,offset);
  242.     pos_objects(header,offset,rscw,rsch);
  243. }
  244.  
  245. #undef adj
  246. #undef adj_menu
  247.